#include "tcpserversocket.h"

#define RECVLENGTH    1024

TcpServerSocket::TcpServerSocket(QObject *parent)
{
    connect(this, SIGNAL(readyRead()), this, SLOT(dataReceived()));
    connect(this, SIGNAL(disconnect()), this, SLOT(slotDisconnected()));
}

void TcpServerSocket::dataReceived()
{
    while(bytesAvailable() > 0)
    {
        int length = bytesAvailable();
        char buf[RECVLENGTH];
        read(buf, RECVLENGTH);
        QString msg = QString(buf);
        emit updateServer(msg, length);
    }
}


void TcpServerSocket::slotDisconnected()
{
    emit disconnected(this->socketDescriptor());
}
